﻿using System;
using System.Data;
using System.Collections.Generic;

using System.Text;

namespace Model
{
    public class UserModel:BaseModel
    {
        public const string TABLE_NAME = "Users";
        public const string USER_ID_FIELD = "UserId";
        public const string USER_NAME_FIELD = "UserName";
        public const string PASS_WORD_FIELD = "Password";
        public const string FIRST_NAME_FIELD = "FirstName";
        public const string LAST_NAME_FIELD = "LastName";
        public const string EMAIL_FIELD = "Email";
        public const string PHONE_FIELD = "Phone"; 
        public const string PHONE_NOTES_FIELD = "PhoneNotes";
        public const string IS_ACTIVE_FIELD = "IsActive";
        public const string IS_ADMIN_FIELD = "UserIsAdmin";
        public const string ROLE_IS_ADMIN_FIELD = "RoleIsAdmin";
        public const string ROLE_ADMIN_NAME_FIELD = "RoleAdminName";

        public UserModel()
            : base(TABLE_NAME, USER_NAME_FIELD)
        {
            
        }

        public void InsertUpdateAddressOfUser(int? AddressId, string UserName, string CompanyName, string Email, string Phone, string Address, string Street1, string Street2, string City, string StateCode, string CountryCode, string ZipCode)
        {
            ExecuteNonDataQuery("InsertUpdateAddressOfUser", AddressId, UserName, CompanyName, Email, Phone, Address, Street1, Street2, City, StateCode, CountryCode, ZipCode);
        }

        public object InsertUpdateUserInfo(int AccountId, int? UserId, string UserName, string Password, string FirstName, string LastName, string Email, string Phone, bool IsAdmin)
        {
           return ExecuteScalar("InsertUpdateUserInfo", AccountId, UserId, UserName, Password, FirstName, LastName, Email, Phone, IsAdmin);
        }

        public void UpdateUserInfo(int UserId, string Password, string FirstName,string LastName, bool IsActive	,bool IsAdmin)
        {
            ExecuteNonDataQuery("UpdateUserInfo",UserId, Password,  FirstName, LastName,  IsActive	, IsAdmin);
        }
        public void InsertUpdateUserRoleAssociation(int UserId,int RoleId,bool IsAllow)
        {
            ExecuteNonDataQuery("InsertUpdateUserRoleAssociation", UserId, RoleId, IsAllow);
        }

        public void DeleteUserByAccountIdAndUserName(int AccountId, string UserName)
        {
            ExecuteNonDataQuery("DeleteUserByAccountIdAndUserName", AccountId, UserName);
        }

        public void DeleteUserByUserId(int UserId)
        {
            ExecuteNonDataQuery("DeleteUserByUserId", UserId);
        }

        public DataRow GetInfoLoginByUserName(string UserName, string Password)
        {
            return GetDataRow(0, "GetInfoLoginByUserName", UserName, Password);
        }

        public DataTable GetAddressInfoByUserId(int UserId)
        {
            return GetDataTable("GetAddressInfoByUserId", UserId);
        }

        public DataTable GetAddressInfoByUserName(int AccountId, string UserName)
        {
            return GetDataTable("GetAddressInfoByUserName", AccountId, UserName);
        }

        public DataRow CheckIsAdminByUserId(int UserId)
        {
            return GetDataRowBySQL("Select * from Users where IsAdmin=1 and AutoId=" + UserId);
        }

        public DataTable GetListUserByAccountId(int AccountId)
        {
            return GetDataTable("GetListUserByAccountId", AccountId);
        }

        public DataTable GetListRoleType()
        {
            return GetDataTable("GetListRoleType");
        }
        
        public DataTable GetListRole()
        {
            return GetDataTable("GetListRole");
        }

        public DataTable GetListUserRoleAssociationByUserIdAndRoleTypeId(int UserId, int RoleTypeId)
        {
            return GetDataTable("GetListUserRoleAssociationByUserIdAndRoleTypeId", UserId, RoleTypeId);
        }

        public void ChangePasswordByUserName(string UserName, string PasswordNew)
        {
            ExecuteNonDataQuery("ChangePasswordByUserName", UserName, PasswordNew);
        }

        public void SetActiveUser(int UserId, bool IsActive)
        {
            ExecuteNonDataQuery("SetActiveUser", UserId, IsActive);
        }

    }
}
